//
//  AnswersTableViewself.m
//  MyProject
//
//  Created by jiaming yan on 2018/3/1.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "AnswersTableViewCell.h"
#import "NSUDManager.h"
#import "QuestionAnwserModel.h"
#import <MJExtension.h>

@implementation AnswersTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    // 加载图片
//    UIImage *image = [UIImage imageNamed:@"Dialogbox"];
//    
//    // 设置左边端盖宽度
//    NSInteger leftCapWidth = image.size.width * 0.5;
//    // 设置上边端盖高度
//    NSInteger topCapHeight = image.size.height * 0.5;
//    
//    UIImage *newImage = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
//
//    self.voiceBackImageView.image = newImage;
    
}

- (void)setModel:(QuestionModel *)questionModel {
    _model = questionModel;
    
    
    self.questionNameL.text = questionModel.content;
    
    self.tagL.text = [NSString stringWithFormat:@"#%@#", questionModel.relatedTag];
    self.countL.text = questionModel.seeCount;
    QuestionAnwserModel *model =  questionModel.anwserModel;
    if (model) {
        self.audioLengthLabel.text = [CommonUtils timeIntervalWithDate:[model.soundLength integerValue]/1000];
        UserModel *user = [NSUDManager currentUser];
        self.voiceView.hidden = YES;
        self.wordView.hidden = YES;
        self.contentLabel.hidden = YES;
        self.publisherL.text = [NSString stringWithFormat:@"%@ | %@ %@",model.publisher,model.positionName,model.companyName];;
        [self.iconIV sd_setImageWithURL:ImageURLWithKey(model.publisherHeadImg) placeholderImage:PlaceholderImagePeople];
        if ([model.anwserType isEqualToString:@"ANWSER_TYPE_SOUND"]) {
            /**语音*/
            self.voiceView.hidden = NO;
            
        }else  if ([model.anwserType isEqualToString:@"ANWSER_TYPE_WORDS"]) {
            /**文字*/
            if (model.isPurchased || [user.userId isEqualToString:[NSString stringWithFormat:@"%zd",model.publisherId]]||[user.userId isEqualToString:self.model.publisherId]) {
                self.contentLabel.hidden = NO;
                self.contentLabel.text = model.content;
                [self.contentLabel sizeToFit];
                self.contentLabelHeight.constant = self.contentLabel.mj_h ;
            }else{
                self.contentLabelHeight.constant = 28;
                self.wordView.hidden = NO;
                self.wordLabel.text = [NSString stringWithFormat:@"1元偷偷看，共%zd个字",model.content.length];
            }
        }
        
        
        if (model.isPurchased) {
            self.wordLabel.text = @"查看";
            self.audioTyepLabel.text = @"播放";
        }else if ([user.userId isEqualToString:[NSString stringWithFormat:@"%zd",model.publisherId]]||[user.userId isEqualToString:self.model.publisherId]) {
            self.wordLabel.text = @"免费查看";
            self.audioTyepLabel.text = @"免费偷听";
        } else{
            self.audioTyepLabel.text = @"1元偷听";
            self.wordLabel.text = [NSString stringWithFormat:@"1元偷偷看，共%zd个字",model.content.length];
        }
    }
    
    
}

@end
